home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- __revision__ = '$Id: message.py 651 2006-08-27 19:26:45Z jajcus $'
- __docformat__ = 'restructuredtext en'
- import libxml2
- from pyxmpp.stanza import Stanza
- from pyxmpp.utils import to_utf8, from_utf8
- from pyxmpp.xmlextra import common_ns
- message_types = ('normal', 'chat', 'headline', 'error', 'groupchat')
-
- class Message(Stanza):
- stanza_type = 'message'
-
- def __init__(self, xmlnode = None, from_jid = None, to_jid = None, stanza_type = None, stanza_id = None, subject = None, body = None, thread = None, error = None, error_cond = None, stream = None):
- self.xmlnode = None
- if isinstance(xmlnode, Message):
- pass
- elif isinstance(xmlnode, Stanza):
- raise TypeError, "Couldn't make Message from other Stanza"
- elif isinstance(xmlnode, libxml2.xmlNode):
- pass
- elif xmlnode is not None:
- raise TypeError, "Couldn't make Message from %r" % (type(xmlnode),)
-
- if xmlnode is None:
- xmlnode = 'message'
-
- Stanza.__init__(self, xmlnode, from_jid = from_jid, to_jid = to_jid, stanza_type = stanza_type, stanza_id = stanza_id, error = error, error_cond = error_cond, stream = stream)
- if subject is not None:
- self.xmlnode.newTextChild(common_ns, 'subject', to_utf8(subject))
-
- if body is not None:
- self.xmlnode.newTextChild(common_ns, 'body', to_utf8(body))
-
- if thread is not None:
- self.xmlnode.newTextChild(common_ns, 'thread', to_utf8(thread))
-
-
-
- def get_subject(self):
- n = self.xpath_eval('ns:subject')
- if n:
- return from_utf8(n[0].getContent())
- else:
- return None
-
-
- def get_thread(self):
- n = self.xpath_eval('ns:thread')
- if n:
- return from_utf8(n[0].getContent())
- else:
- return None
-
-
- def copy(self):
- return Message(self)
-
-
- def get_body(self):
- n = self.xpath_eval('ns:body')
- if n:
- return from_utf8(n[0].getContent())
- else:
- return None
-
-
- def make_error_response(self, cond):
- if self.get_type() == 'error':
- raise ValueError, 'Errors may not be generated in response to errors'
-
- m = Message(stanza_type = 'error', from_jid = self.get_to(), to_jid = self.get_from(), stanza_id = self.get_id(), error_cond = cond)
- if self.xmlnode.children:
- n = self.xmlnode.children
- while n:
- m.xmlnode.children.addPrevSibling(n.copyNode(1))
- n = n.next
-
- return m
-
-
-